package com.hxzy.controller.front.merchandiser;

import com.github.pagehelper.PageInfo;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.resp.PageResp;
import com.hxzy.common.resp.R;
import com.hxzy.common.wrap.PageInfoUtil;
import com.hxzy.controller.front.merchandiser.req.EnterpriseInfoReq;
import com.hxzy.controller.front.merchandiser.req.EnterpriseReq;
import com.hxzy.controller.front.merchandiser.resp.EnterpriseResp;
import com.hxzy.service.MerchandiserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;

/**
 * @Author wy
 * @Description TODO
 * @Date 2023/9/25 14:15
 * @Version 1.0
 */
@Api(tags = "手机端-商家")
@RestController
@RequestMapping(value = "/front/enterprise")
public class FrontMerchandiserController {

    @Autowired
    private MerchandiserService merchandiserService;

    @ApiOperation(value = "商家分页查询")
    @GetMapping(value = "/data")
    public R<PageResp<EnterpriseResp>> search( @Valid EnterpriseReq req){
        PageInfo<EnterpriseResp> pageInfo= this.merchandiserService.frontSearch(req);
        PageResp<EnterpriseResp> resp = PageInfoUtil.pageInfoToResp(pageInfo);
        return R.okHasData(resp);
    }

    @ApiOperation(value = "查询商家信息")
    @GetMapping(value = "/findById")
    public R<EnterpriseResp> findById(@Valid EnterpriseInfoReq req ){
        EnterpriseResp resp=this.merchandiserService.findbyId(req);
        if(Objects.isNull(resp)){
            return R.build(AckCode.NOT_FOUND_DATA);
        }
        return R.okHasData(resp);
    }

}
